//
//  KeleNavigationController.m
//  KeleAppProject
//
//  Created by Cen Zhou on 2018/1/10.
//  Copyright © 2018年 Cen Zhou. All rights reserved.
//

#import "KeleNavigationController.h"

@interface KeleNavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation KeleNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.interactivePopGestureRecognizer.delegate = self;
    [self setupUI];
}

+ (void)initialize
{
    // 设置导航栏的样式
    [self setupNavigationBarTheme];
}

- (void)setupUI {
    
    [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [self.navigationBar setShadowImage:[UIImage new]];
    self.navigationBar.barTintColor = [UIColor whiteColor];
    self.navigationBar.translucent = NO;  // NO从导航栏下开始计算   YES 从顶部开始计算
    
    self.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:KLColor_B6};
    
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
}


/**
 *  设置导航栏的样式
 */
+ (void)setupNavigationBarTheme
{
    UINavigationBar *navBar = [UINavigationBar appearance];
    // navBar.translucent = NO;
    
    // 设置标题文字颜色
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSFontAttributeName] = [UIFont fontWithName:@"PingFang-SC-Medium" size:18];
    textAttrs[NSForegroundColorAttributeName] = KLColor_B6;
    [navBar setTitleTextAttributes:textAttrs];
}

/**
 *  拦截导航控制器的push操作
 */
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if(self.viewControllers.count > 0){
        viewController.hidesBottomBarWhenPushed = YES;
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImageName:@"icon_fanhui" highImageName:@"icon_fanhui" target:self action:@selector(back)];
    }
    
    [super pushViewController:viewController animated:animated];
}

- (void)back
{
    [self popViewControllerAnimated:YES];
}

#pragma mark - <UIGestureRecognizerDelegate>
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    return self.viewControllers.count > 1;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
